let postUrl;
if (process.env.NODE_ENV === 'development') {
	// #ifdef APP-PLUS
	postUrl = 'https://newartapi.jimuzhou.cloud/'
	// #endif
	// #ifndef APP-PLUS
	postUrl = 'http://localhost:3308/'
	//postUrl = 'https://artapi.jimuzhou.cloud/'
	// #endif
} else {
	postUrl = 'https://newartapi.jimuzhou.cloud/'
}
export default {
	baseUrl: postUrl, // 导出baseUrl供外部使用
	Post(name, params = {}, loadingText) {
		let token = "";
		if (uni.getStorageSync("token")) {
			token = uni.getStorageSync("token")
		}
		params.source = "PC"
		params.isAdmin = true
		if (loadingText) {
			uni.showLoading({
				title: loadingText
			})
		}
		return new Promise((resolve, reject) => {
			uni.request({
				url: postUrl + name, //仅为示例，并非真实接口地址。
				data: params,
				method: 'POST',
				header: {
					"token": token,
					"content-type": "application/json"
				},
				timeout: 6000000000,
				success: (res) => {
					if (process.env.NODE_ENV === 'development') {
						console.log(name, res.data)
					}
					if (res.data.code == 1) {
						resolve(res.data)
					} else if (res.data.code == 401 || res.data.code == 3 || res.data.code == 4) {
						setTimeout(function() {
							uni.showToast({
								"icon": "none",
								"title": res.data.msg
							})
						}, 1000)
						uni.reLaunch({
							url: "/pages/login/login"
						})
					} else {
						uni.showToast({
							"icon": "none",
							"title": res.data.msg
						})
						reject(res.data)
					}
					uni.hideLoading()
				}
			});
		})
	},



	Get(name, params = {}, loadingText) {
		let postUrl = "https://poster.miaogeban.com/poster/"
		if (loadingText) {
			uni.showLoading({
				title: loadingText
			})
		}
		return new Promise((resolve, reject) => {
			uni.request({
				url: postUrl + name, //仅为示例，并非真实接口地址。
					data: params,
					method: 'GET',
					header: {
						//"token": token,
						"content-type": "application/json"
					},
					timeout: 6000000000,
					success: (res) => {
						if (process.env.NODE_ENV === 'development') {
							console.log(name, res.data)
						}
						if (res.data.code == 0) {
							resolve(res.data)
						} else if (res.data.code == 401 || res.data.code == 3 || res.data.code == 4) {
							setTimeout(function() {
								uni.showToast({
									"icon": "none",
									"title": res.data.msg
								})
							}, 1000)
							uni.reLaunch({
								url: "/pages/login/login"
							})
						} else {
							uni.showToast({
								"icon": "none",
								"title": res.data.msg
							})
							reject(res.data)
						}
						uni.hideLoading()
					}
			});
		})
	}
}